//
//  ViewController.m
//  runtimeTest
//
//  Created by Song on 2018/4/17.
//  Copyright © 2018年 Song. All rights reserved.
//

#import "ViewController.h"
#import "NSObject+JSONExtension.h"
#import "User.h"
#import "Book.h"


@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSString * str = NSStringFromClass([User class]);
    NSLog(@"%@",str);
    
    [self json];
}

/// 字典转模型demo
- (void)json {
    
    
//    NSString *path = [[NSBundle mainBundle] pathForResource:@"model.json" ofType:nil];
//    NSData *jsonData = [NSData dataWithContentsOfFile:path];
//    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:NULL];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"model.json" ofType:nil];
    NSData *jsonData = [NSData dataWithContentsOfFile:path];
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
    
    NSLog(@"%@",json);
    
    User *user = [User GGGGGGGobjectWithDict:json]; // 字典转模型
    NSLog(@"\n");
    NSLog(@"user.name = %@",user.name);
    NSLog(@"user.cat = %@",user.cat);
    NSLog(@"user.cat.name = %@",user.cat.name);
    NSLog(@"user.cat.fish.weight = %f",user.cat.fish.weight);
    
    Book *book = user.books[0];
    NSLog(@"book.name = %@",book.name);
    
//    User *user = [[User alloc] initWithDict:json];
//    NSLog(@"%@",user.cat);
//    NSLog(@"=== %@",user.cat.name);
    
}

@end
/*
 ,
 
 
 "books" : [
 {
 "name" : "C语言程序设计",
 "price" : 20.8,
 "publisher" : "清华大学出版社"
 },
 {
 "name" : "乔布斯传",
 "price" : 50.2,
 "publisher" : "苹果出版社"
 }
 ]
 */
